var app = new Vue({
    el: "#transferCenter",
    data() {
        return {
            showDialog: true, // 加入购物车弹出层是否显示
            outOfStock_popup: false,
            otherMarket: false,
            quantity: '',
            errMsg: '',
            orderTitle: [ // 头部
                {
                    title: '截止时间',
                    type: '进行中',
                    status: 'PROCURING'
                },
                {
                    title: '完成时间',
                    type: '待发货',
                    status: 'WAIT_OUT'
                },
                {
                    title: '完成时间',
                    type: '已完成',
                    status: 'FINISHED'
                }
            ],
            listData: [],
            orderType: 0, // 进行中：0，待发货：1,已完成:2
            currentPage: 0,// 当前页数
            totalPage: 2, // 总页数
            loading: false,
            orderInfo: {}, // 采买订单详情
            goodsIndex: 0,
        }
    },
    mounted() {
    },
    methods: {
        // 更改采买类型tab
        changeOrderType(index) {
            let self = this
            self.orderType = index
            self.loading = true
            self.currentPage = 1
            self.listData = []
            let status = self.orderTitle[index].status
            self.getData(status)
        },
        // 滚动加载
        loadMore() {
            let self = this
            let status = self.orderTitle[self.orderType].status
            self.currentPage++
            if (self.currentPage > self.totalPage) {
                self.loading = true
                return false
            }
            self.getData(status)
        },
        //获取未收货列表
        getData(status) {
            let self = this
            let api = ''
            switch (status) {
                case 'PROCURING':
                    api = 'procurement/procurement/getNotReceivingGoods.do'
                    break;
                case 'WAIT_OUT':
                    api = 'procurement/procurement/getNotDeliverGoods.do'
                    break;
                case 'FINISHED':
                    api = 'procurement/procurement/getDeliverGoodsList.do'
                    break;
            }
            Axios.post(api, {
                pageSize: 6,
                currentPage: self.currentPage,
            }).then(function (data) {
                if (data.respCode === 'S') {
                    if (self.currentPage == 1) {
                        self.listData = data.data.data
                    } else {
                        self.listData = self.listData.concat(data.data.data)
                    }
                    self.totalPage = data.data.totalPage

                    if (self.currentPage < self.totalPage) {
                        self.loading = false
                    }
                } else {
                    self.listData = []
                }
            })
        },
        //确认收货/发货
        confirm(procurementTaskIdList, index) {
            let self = this
            let api = ''
            let status = self.orderTitle[self.orderType].status
            if (status === 'PROCURING') {
                api = 'procurement/procurement/confirmGoods.do'
            } else {
                api = 'procurement/procurement/confirmDeliverGoods.do'
            }
            Axios.post(api, {
                pageSize: 5,
                procurementTaskIdList: procurementTaskIdList,
            }).then(function (data) {
                if (data.respCode === 'S') {
                    self.listData.splice(index, 1)
                } else {
                    self.errMsg = data.errorType
                    setTimeout(() => {
                        self.errMsg = ''
                    }, 1000);
                }
            })
        },
        timestaConversionmp(date) {
            let self = this
            let time = new Date(date)
            let year = time.getFullYear()
            // let y = year.toString().slice(2)
            let m = time.getMonth() + 1
            let d = time.getDate()
            let h = time.getHours()
            let mm = time.getMinutes()
            let s = time.getSeconds()
            let ms = time.getMilliseconds()
            return year + '-' + self.dateFormat(m) + '-' + self.dateFormat(d) + ' ' + self.dateFormat(h) + ':' + self.dateFormat(mm) + ':' + self.dateFormat(s) + ':' + ms
        },
        dateFormat(t) {
            return t < 10 ? '0' + t : t
        },
        format(date) {
            if (date) {
                let d = new Date(date).Format('yy-MM-dd hh:mm:ss'); //"2018-11-15 17:40:00"
                return d;
            }
        }
    }
})
